package com.example.myblog.controller;


import com.example.myblog.entity.Follow;
import com.example.myblog.exception.BaseException;
import com.example.myblog.result.ResponseBean;
import com.example.myblog.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 关注表 前端控制器
 * </p>
 *
 * @author 叶兴
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/follow")
public class FollowController {

    FollowService followService;

    @Autowired
    public void setFollowService(FollowService followService) {
        this.followService = followService;
    }

    /**
     * 关注一个用户
     * @param followName
     * @return
     * @throws BaseException
     */
    @PostMapping("/{followname}")
    public ResponseBean followUser(@PathVariable String followname) throws BaseException {
        followService.followUser(followname);
        return ResponseBean.success();
    }

    /**
     * 取关一个用户
     * @param followname
     * @return
     * @throws BaseException
     */
    @PostMapping("/cancel/{followname}")
    public ResponseBean cancel(@PathVariable String followname) throws BaseException {
        followService.cancel(followname);
        return ResponseBean.success();
    }

    /**
     * 获取当前用户的关注列表
     * @return
     * @throws BaseException
     */
    @GetMapping("/follows")
    public ResponseBean list() throws BaseException {
        List<Follow> list = followService.getFollows();
        return ResponseBean.success(list);
    }

}
